/**
 * 
 */
package com.gragra.sampling.nonproj;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import com.gragra.sampling.PopulationProbabilityAssigner;
import com.gragra.sampling.PopulationSamplingStructure;
import com.gragra.sampling.binary.ConvertSample;
import com.gragra.sampling.binary.HeadAssignmentStructure;
import com.gragra.sampling.binary.ThreadedToString;
/**
 * @author Christoph Teichmann
 * 05.10.2013
 */
public class HeadFrequenciesUnconverted implements ConvertSample
{
	/**
	 * 
	 */
	private final Object2IntOpenHashMap<String> counts = new Object2IntOpenHashMap<String>();
	/* (non-Javadoc)
	 * @see com.gragra.sampling.binary.ConvertSample#getBest(com.gragra.sampling.PopulationSamplingStructure, com.gragra.sampling.PopulationProbabilityAssigner)
	 */
	@Override
	public String getBest(PopulationSamplingStructure str,
			PopulationProbabilityAssigner pa)
	{return null;}
	/* (non-Javadoc)
	 * @see com.gragra.sampling.binary.ConvertSample#minRisk(com.gragra.sampling.PopulationSamplingStructure, com.gragra.sampling.PopulationProbabilityAssigner)
	 */
	@Override
	public String minRisk(PopulationSamplingStructure str,
			PopulationProbabilityAssigner pa)
	{return null;}
	/* (non-Javadoc)
	 * @see com.gragra.sampling.binary.ConvertSample#addSample(com.gragra.sampling.PopulationSamplingStructure)
	 */
	@Override
	public void addSample(PopulationSamplingStructure str)
	{
		HeadAssignmentStructure has = (HeadAssignmentStructure) str;
		ThreadedToString tts = (ThreadedToString) has;
		for(int thread=0;thread<tts.getNumberOfThreads();++thread)
		{counts.addTo(makeHeadString(str,thread), 1);}
	}
	/**
	 * 
	 * @param str
	 * @param thread
	 * @return
	 */
	private String makeHeadString(PopulationSamplingStructure str, int thread)
	{
		StringBuilder sb = new StringBuilder();
		HeadAssignmentStructure has = (HeadAssignmentStructure) str;
		for(int i=0;i<has.getLength();++i)
		{
			if(i!=0)
			{sb.append(" ");}
			sb.append(has.getHeadPosition(i, thread));
		}
		return sb.toString();
	}
	/* (non-Javadoc)
	 * @see com.gragra.sampling.binary.ConvertSample#setBest(com.gragra.sampling.PopulationSamplingStructure, int)
	 */
	@Override
	public void setBest(PopulationSamplingStructure str, int thread)
	{}
	/* (non-Javadoc)
	 * @see com.gragra.sampling.binary.ConvertSample#getNumberSeen(java.lang.String)
	 */
	@Override
	public double getNumberSeen(String goldTwo)
	{return counts.getInt(goldTwo);}
	/**
	 * 
	 * @return
	 */
	public Object2IntOpenHashMap<? extends Object> getCounts()
	{return counts;}
}